package com.specialized.driver.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.specialized.common.core.domain.Result;
import com.specialized.orders.common.domain.RealTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.specialized.common.security.annotation.RequiresPermissions;
import com.specialized.driver.domain.Driver;
import com.specialized.driver.service.IDriverService;
import com.specialized.common.core.web.controller.BaseController;
import com.specialized.common.core.utils.poi.ExcelUtil;

/**
 * 司机Controller
 *
 * @author djh
 * @date 2024-07-22
 */
@RestController
@RequestMapping("/Driver")
public class DriverController extends BaseController {
    @Autowired
    private IDriverService driverService;

/**
 * 查询司机列表
 */
@RequiresPermissions("driver:Driver:list")
@GetMapping("/list")
    public Result list(Driver driver) {
        startPage();
        List<Driver> list = driverService.selectDriverList(driver);
        return getDataTable(list);
    }

    /**
     * 导出司机列表
     */
    @RequiresPermissions("driver:Driver:export")
//    @Log(title = "司机", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Driver driver) {
        List<Driver> list = driverService.selectDriverList(driver);
        ExcelUtil<Driver> util = new ExcelUtil<Driver>(Driver. class);
        util.exportExcel(response, list, "司机数据");
    }

    /**
     * 获取司机详细信息
     */
    @RequiresPermissions("driver:Driver:query")
    @GetMapping(value = "/{driverId}")
    public Result getInfo(@PathVariable("driverId") Long driverId) {
        return success(driverService.selectDriverByDriverId(driverId));
    }

    /**
     * 新增司机
     */
    @RequiresPermissions("driver:Driver:add")
//    @Log(title = "司机", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Driver driver) {
        return toAjax(driverService.insertDriver(driver));
    }

    /**
     * 修改司机
     */
    @RequiresPermissions("driver:Driver:edit")
//    @Log(title = "司机", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Driver driver) {
        return toAjax(driverService.updateDriver(driver));
    }

    /**
     * 删除司机
     */
    @RequiresPermissions("driver:Driver:remove")
//    @Log(title = "司机", businessType = BusinessType.DELETE)
    @DeleteMapping("/{driverIds}")
    public Result remove(@PathVariable Long[] driverIds) {
        return toAjax(driverService.deleteDriverByDriverIds(driverIds));
    }



    /**
     * 司机接单
     */
    @PostMapping("/updOrdersStatusDriver")
    public Result updOrdersStatusDriver(@RequestBody RealTime realTime) {
        driverService.updOrdersStatusDriver(realTime);
        return Result.success();
    }







}
